/*
 * @Author: Eureka 
 * @Date: 2020-09-10 14:56:30 
 * @Last Modified by: Eureka
 * @Last Modified time: 2022-05-02 12:17:55
 */

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_swiper_null_safety_flutter3/flutter_swiper_null_safety_flutter3.dart';
import 'package:senkoo_platform/Utils/base_standard.dart';
import 'package:senkoo_platform/Utils/base_text.dart';
import 'package:senkoo_platform/Utils/hex_color_utils.dart';
import 'package:senkoo_platform/Utils/set_edge_insets.dart';
import 'package:senkoo_platform/base_image/image_utils.dart';
import 'package:senkoo_platform/base_image/load_image.dart';
import 'package:senkoo_platform/base_message/sp_constanst.dart';
import 'package:senkoo_platform/base_widget/base_widget.dart';
import 'package:senkoo_platform/config/config.dart';
import 'package:senkoo_platform/views/main_modular/main_page.dart';
import 'package:senkoo_platform/views/splash_mudular/limits_authority_page.dart';
import 'package:sp_util/sp_util.dart';

class SplashPage extends StatefulWidget {
  const SplashPage({
    super.key,
  });

  @override
  State<SplashPage> createState() => _SplashPageState();
}

class _SplashPageState extends State<SplashPage> {
  StreamSubscription? _subscription;

  // 动画控制器
  // BobMinionController? _flareControls;

  final List _swiperBriefList = [
    {
      'title': "无忧结算",
      'brief': "一键发起提现申请\n平台审核快速结算",
      'img': 'guidepages/Icon_Viewpager_Image_1'
    },
    {
      'title': "值得信赖",
      'brief': "平台提供海量的广告安装工单\n工匠主动接单，还可以提前储备下一个单\n接单更连续更灵活",
      'img': 'guidepages/Icon_Viewpager_Image_2'
    },
    {
      'title': "价格透明",
      'brief': "智能派单平台统一合理定价\n无需与客户议价，省时省心一拍即合",
      'img': 'guidepages/Icon_Viewpager_Image_3'
    },
  ];

  @override
  void initState() async {
    // setTopBarVisible(false);
    // setAppBarVisible(false);
    await _initSplash();

    // WidgetsBinding.instance.addPostFrameCallback((_) async {
    //   // 由于SpUtil未初始化，所以MaterialApp获取的为默认主题配置，这里同步一下。
    //   // Provider.of<ThemeProvider>(context).syncTheme();
    //   if (SpUtil.getBool(SpConstanst.keyGuide, defValue: true)!) {
    //     /// 预先缓存图片，避免直接使用时因为首次加载造成闪动
    //     _swiperBriefList.asMap().forEach((index, image) {
    //       precacheImage(ImageUtils.getAssetImage(image['img']), context);
    //     });
    //   }
    // });

    super.initState();
  }

  @override
  void dispose() {
    _subscription?.cancel();
    super.dispose();
  }

  Future<void> _initSplash() async {
    if (SpUtil.getString(SpConstanst.authoriation)!.isNotEmpty) {
      AppConfig.authoriationToken = SpUtil.getString(SpConstanst.authoriation);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.blue,
    );
  }
  //   if (SpUtil.getString(SpConstanst.authoriation)!.isNotEmpty) {
  //     return MainPage();
  //   } else {
  //     return Container(
  //       height: MediaQuery.of(context).size.height,
  //       width: MediaQuery.of(context).size.width,
  //       color: Standard.colorFAFAFA,
  //       child: SafeArea(
  //         top: false,
  //         child: Swiper(
  //           key: const Key('swiper'),
  //           itemCount: _swiperBriefList.length + 1,
  //           loop: false,
  //           itemBuilder: (_, index) {
  //             if (index < _swiperBriefList.length) {
  //               return Column(
  //                 mainAxisAlignment: MainAxisAlignment.center,
  //                 crossAxisAlignment: CrossAxisAlignment.center,
  //                 children: [
  //                   Center(
  //                     child: Column(
  //                       children: [
  //                         SizedBox(
  //                           width: 300.w,
  //                           height: 300.w,
  //                           child: LoadAssetImage(
  //                             _swiperBriefList[index]['img'],
  //                             fit: BoxFit.contain,
  //                           ),
  //                         ),
  //                         text(
  //                           textString: '${_swiperBriefList[index]['title']}',
  //                           textColor: Standard.color333333,
  //                           textWeight: semibold,
  //                           textSize: 36.sp,
  //                         ),
  //                         Padding(
  //                           padding: setEdgeInsets(top: 19),
  //                           child: text(
  //                               textString:
  //                                   '${_swiperBriefList[index]['brief']}',
  //                               textColor: Standard.color999999,
  //                               textSize: 16.sp,
  //                               textAligin: textAlignCenter),
  //                         ),
  //                       ],
  //                     ),
  //                   ),
  //                 ],
  //               );
  //             } else {
  //               return LimitsAuthorityPage();
  //             }
  //           },
  //           pagination: SwiperPagination(
  //               builder: DotSwiperPaginationBuilder(
  //                   size: 8,
  //                   color: HexColor('#E5E9F2'),
  //                   activeColor: HexColor('#333333'),
  //                   activeSize: 8,
  //                   space: 6)),
  //         ),
  //       ),
  //     );
  //   }
  // }
}
